﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
//using BySoft.Server.Business.UserCode;
using BySoft.Server.Common.Enum;
using BySoft.Server.Business;
using BySoft.Web.Utility;
using BySoft.Server.Common.Entity;
using BySoft.Server.Consts;
using BySoft.Server.Common;
using System.Data;
using OneSoft.EntityCore;
using System.Web.UI.HtmlControls;
using System.Configuration;
using System.IO;
using System.Text;

namespace TaiChySystem.Web.Site.ComPage
{
    public partial class UpFile : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                
            }
        }

        private bool SaveFile(string strFileName)
        {
            if (fimport.HasFile)
            {
                fimport.SaveAs(strFileName);
                return true;
            }
            else
            {
                return false;
            }
        }

        protected void btnOk_Click(object sender, EventArgs e)
        {
            //string sReturn = "";
            //string strFileName = Server.MapPath("~/Module/" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls");
            //if (SaveFile(strFileName))
            //{
            //    DataTable dt = ClsComm.ExcelDataSource(strFileName);
            //    File.Delete(strFileName);

            //    Dictionary<string, string> lst = GetMariterType(dt);
            //    if (lst.Count > 0)
            //    {
            //        List<MdMaterialEntity> lstbody = new List<MdMaterialEntity>();
            //        string strErrType = "";
            //        foreach (DataRow item in dt.Rows)
            //        {
            //            string strType = CommonMethod.GetString(item["所属分类"]);
            //            if (lst.ContainsKey(strType))
            //            {
            //                strType = lst[strType];
            //            }
            //            else
            //            {
            //                strErrType += "所属分类[" + strType + "]不存在，请先添加该分类！<br />";
            //                continue;
            //            }

            //            MdMaterialEntity entity = new MdMaterialEntity();
            //            entity.MaterialName = CommonMethod.GetString(item["名称"]);
            //            entity.PictureNum = CommonMethod.GetString(item["图号"]);
            //            entity.UfidaCode = CommonMethod.GetString(item["用友编码"]);
            //            entity.Trademark = CommonMethod.GetString(item["材料牌号"]);
            //            entity.MaterialTypeID = strType;
            //            entity.OutlineSize = CommonMethod.GetString(item["外形尺寸"]);
            //            if (!string.IsNullOrEmpty(CommonMethod.GetString(item["厚度"])))
            //            {
            //                entity.Thickness = CommonMethod.ConvertToInt(item["厚度"]);
            //            }
            //            if (!string.IsNullOrEmpty(CommonMethod.GetString(item["单重"])))
            //            {
            //                entity.UnitWeight = CommonMethod.ConvertToDecimal(item["单重"]);
            //            }
            //            entity.Remark = CommonMethod.GetString(item["备注"]);
            //            entity.Status = "1";
            //            entity.CreateUserId = CurrentUser.UserID;
            //            entity.CreateUserName = CurrentUser.UserName;
            //            entity.CreateDate = DateTime.Now;
            //            entity.ModifyUserId = CurrentUser.UserID;
            //            entity.ModifyUserName = CurrentUser.UserName;
            //            entity.ModifyDate = DateTime.Now;

            //            if (ClsComm.CheckExist("MD_Material", "PictureNum", entity.PictureNum,true))
            //            {
            //                UIHelper.AlertMessage(this.Page, "图号" + entity.PictureNum + "已经存在");
            //                return;
            //            }
            //            if (ClsComm.CheckExist("MD_Material", "UfidaCode", entity.UfidaCode,true))
            //            {
            //                UIHelper.AlertMessage(this.Page, "用友编号" + entity.PictureNum + "已经存在");
            //                return;
            //            }
            //            lstbody.Add(entity);
            //        }
            //        if (!string.IsNullOrEmpty(strErrType))
            //        {
            //            UIHelper.AlertMessage(this.Page, strErrType);
            //            return;
            //        }
            //        MdMaterial.Save(lstbody);
            //        sReturn = "success";                    
            //    }
            //}   
            //ClientScript.RegisterStartupScript(this.GetType(), "", "<script>setCookie(dialogReturn_key,'" + sReturn + "',1);CloseTopDialog();</script>");
        }

        private Dictionary<string, string> GetMariterType(DataTable dt)
        {
            Dictionary<string, string> lst = new Dictionary<string, string>();
            //DataTable dtlst = MdMaterialtype.SelectHead(dt);
            //if (dtlst == null || dtlst.Rows.Count < 1)
            //{
            //    return lst;
            //}
            //foreach (DataRow item in dtlst.Rows)
            //{
            //    lst.Add(item["MaterialTypeName"].ToString(), item["MaterialTypeID"].ToString());
            //}
            return lst;
        }
    }
}